package
{
	import api.dataStruct.InitAPIObj;
	import api.event.CallFunName;
	
	import base.GlobalData;
	
	import com.game.GameLoadThis;
	import com.game.display.DisManage;
	import com.game.utils.GlobalFun;
	
	import flash.display.LoaderInfo;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.ui.ContextMenu;
	import flash.ui.ContextMenuItem;
	
	import main.InitAPI;
	
	public class Main extends MovieClip
	{
		private var _disMange:DisManage=new DisManage()
		public function Main()
		{
			this.addEventListener(Event.ADDED_TO_STAGE,toStage);
		}
		private function toStage(e:Event):void{
			this.removeEventListener(Event.ADDED_TO_STAGE,toStage);
			
			GlobalData.isHttp=GlobalFun.CheckHttp(this .stage.loaderInfo.url);
			
			
			stop();
			
			setRightMenu();
			addBg();
			
			initLoading();
			addChild(_disMange);
		
		}
		private function setRightMenu():void{
			var myContextMenu:ContextMenu = new ContextMenu();
			var more:ContextMenuItem = new ContextMenuItem("游戏版本:1.0",false,false);
			myContextMenu.customItems.push(more);
			myContextMenu.hideBuiltInItems()
			this.contextMenu = myContextMenu;
		}
		private function addBg():void{
			addChild(GlobalFun.getRect(GlobalData.gameW,GlobalData.gameH));
		}
		private function initLoading():void
		{
			var _initObj:InitAPIObj=GlobalData.getInitAPIObj();
			var _isShowLogo:Boolean=false;
			if(_initObj.type==1||_initObj.type==5){
				_isShowLogo=true;
			}
			new GameLoadThis(this,loadGameCom,GlobalData.gameW,GlobalData.gameH,GlobalData.isHttp,_isShowLogo);
		}
		private function loadGameCom(loaderInfo:LoaderInfo):void{
			trace("loadGameCom")
			GlobalData.apiCore.init(DisManage._alertSP,loaderInfo);
			GlobalData.apiCore.callAPIFun(CallFunName.A_DIS_INIT_CLEW,"正在加载配置文件");
			gotoAndStop(2);
			new InitAPI();
		}
		
	}
}